const db = require("../utils/db");

// 近七日就诊情况
exports.countState = async (params) => {
    return new Promise(((resolve, reject) => {
        let sql = `select * from countstate where hospital = ${params.hospital}`
        db.query(sql).then(res => {
            console.log(res, "countState sql查询成功结果")
            let key = [],value = [],result = {};
            for(let item in res[0]){
                key.push(item);
                value.push(res[0][item]);
            }
            result.key = key.slice(1,key.length-1);
            result.value = value.slice(1,value.length-1);
            result.count = res[0] ? res[0].countState : 0;
            resolve(result);
        }).catch(error => {
            console.log(error, "patientListGet sql查询失败结果")
            reject(error)

        })
    }))
}

// 统计-获取医生患者统计
exports.countDocPatient = async () => {
    return new Promise(((resolve, reject) => {
        let sql = `select * from docpatient`
        db.query(sql).then(res => {
            console.log(res, "countDocPatient sql查询成功结果")
            let key = [],value = [],result = {};
            for(let item in res[0]){
                key.push(item);
                value.push(res[0][item]);
            }
            result.key = key.slice(1);
            result.value = value.slice(1);
            result.count = res[0].count;
            resolve(result);
        }).catch(error => {
            console.log(error, "patientListGet sql查询失败结果")
            reject(error)

        })
    }))
}
